<template>
  <div class="login_container">
    <div class="login_box">
      <!-- 头像区 -->
      <div class="avatar_box">
        <img src="../assets/dyz.jpg" alt />
      </div>
      <!-- 登录表单区 -->
      <el-form ref="loginForm" :model="loginForm" :rules="rules" label-width="0px" class="login_form">
        <!-- 用户名 -->
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" prefix-icon="iconfont icon-zhanghao" />
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" prefix-icon="iconfont icon-mima" type="password" />
        </el-form-item>
        <!-- 验证码区 -->
        <div class="join_formitem">
          <!-- <label class="enquiry">验证码<span>:</span></label> -->
          <div class="captcha">
            <input type="text" placeholder="请输入验证码" class="yanzhengma_input" />
            <!-- <input type="button" class="verification" v-model="checkCode"/> -->
            <div class="verification"><img src="" alt="" /></div>
          </div>
        </div>
        <!-- 按钮区 -->
        <el-form-item class="btns">
          <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
          <el-button type="info" @click="resetloginForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      // 登录表单的数据对象
      loginForm: {
        username: '',
        password: '',
      },
      // 这是表单的验证规则对象
      rules: {
        username: [
          { required: true, message: '请输入您的名称', trigger: 'blur' },
          {
            min: 3,
            max: 10,
            message: '长度在 3 到 10 个字符',
            trigger: 'blur',
          }
        ],
        password: [
          { required: true, message: '请输入您的密码', trigger: 'blur' },
          {
            min: 6,
            max: 10,
            message: '长度在 6 到 10 个字符',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  // created () {
  //   this.createCode ()
  // },
  mounted () {
    this.$axios.get('api/auth/imgCode').then(res => {
      console.log(res.data.data)
      this.imgCode = res.data.data.img
    })
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },
    resetloginForm () {
      this.$refs.loginForm.resetFields()
    },
    createCode () {
      // 先清空验证码的输入
      this.code = ''
      this.checkCode = ''
      this.picLyanzhengma = ''
      // 验证码的长度
      // let codeLength = 4
    }
  },
}
</script>

<style lang="less" scoped>
.login_container {
  position: relative;
  background-color: #2b4b6b;
  height: 100%;
}
.login_box {
  width: 450px;
  height: 360px;
  background-color: aliceblue;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  .avatar_box {
    width: 130px;
    height: 130px;
    border: 1px solid #eee;
    border-radius: 50%;
    padding: 10px;
    background-color: #eee;
    box-shadow: 0 0 10px #ddd;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
    }
  }
}
.btns {
  display: flex;
  justify-content: flex-end;
}
.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
  }
.yanzhengma_input{
    font-family: 'Exo 2', sans-serif;
    border: 1px solid #fff;
    color: #fff;
    outline: none;
    border-radius: 12px;
    letter-spacing: 1px;
    font-size: 17px;
    font-weight: normal;
    background-color: rgba(82, 56, 76, 0.15);
    padding: 5px 0 5px 10px;
    height: 30px;
    border: 1px solid #e6e6e6;
}
.verification{
    float: right;
    border-radius: 12px;
    width:120px;
    height: 35px;
    letter-spacing:5px;
    margin-left: 20px;
    transform: translate(-15px,0);
    border: 1px solid #ddd;
    img {
      width: 100%;
      height: 100%;
    }
}
.captcha{
    height: 50px;
    text-align: justify;
}
</style>
